﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Kinect;
using BicycleTrafficSimulator.DataModel;
using System.Threading;

namespace BicycleTrafficSimulator.DataModel
{
    public class Tree : AbstractModel, IGameObject
    {
            public Tree(Vector3 position)
            {
                this.Position = position;
                this.Rotation = 0f;
                this.Scale = new Vector3(0.0005f, 0.0010f, 0.0005f);
            }

            public void LoadContent(ContentManager content, String modelName)
            {
                this.Model = content.Load<Model>(modelName);

            }

            public void Update(GameTime gameTime)
            {
                
            }


            public void Draw(Matrix viewMatrix, Matrix projectionMatrix)
            {
                // Copy any parent transforms.
                Matrix[] transforms = new Matrix[this.Model.Bones.Count];
                //  float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
                this.Model.CopyAbsoluteBoneTransformsTo(transforms);

                // Draw the model. A model can have multiple meshes, so loop.
                foreach (ModelMesh mesh in this.Model.Meshes)
                {
                    // This is where the mesh orientation is set, as well 
                    // as our camera and projection.
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.World = transforms[mesh.ParentBone.Index] *
                            Matrix.CreateScale(this.Scale.X, this.Scale.Y, this.Scale.Z) * Matrix.CreateRotationY(MathHelper.Pi) *
                            Matrix.CreateRotationY(this.Rotation)
                            * Matrix.CreateTranslation(this.Position);
                        effect.View = viewMatrix;
                        effect.Projection = projectionMatrix;
                    }
                    // Draw the mesh, using the effects set above.
                    mesh.Draw();
                }
            }

        
    }
}
